﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System.Text.RegularExpressions;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;

namespace DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects
{
    public class ModuleActionMenu : WatiNBase
    {
        #region Constructors

        public ModuleActionMenu(WatiNBase watinBase) : base(watinBase.IEInstance, watinBase.SiteUrl, watinBase.DBName) { }

        public ModuleActionMenu(IE ieInstance, string siteUrl, string dbName) : base(ieInstance, siteUrl, dbName) { }

        #endregion

        #region Public Properties

        #region Spans
        public Span EditExtensionTitle
        {
            get { return IEInstance.Span(Find.ById(s => s.EndsWith("EditExtension_lblTitle"))); }
        }
        public Span InstallModuleActionMenuItem
        {
            get { return IEInstance.Span(Find.ByText("Install Module")); }
        }
        public Span CreateNewModuleActionMenuItem
        {
            get { return IEInstance.Span(Find.ByText("Create New Module")); }
        }
        public Span HelpActionMenuItem
        {
            get { return ActionMenuBody.Span(Find.ByText("Help")); }
        }
        public Span OnlineHelpActionMenuItem
        {
            get { return ActionMenuBody.Span(Find.ByText("Online Help")); }
        }
        public Span PrintActionMenuItem
        {
            get { return ActionMenuBody.Span(Find.ByText("Print")); }
        }
        public Span ViewSourceActionMenuItem
        {
            get { return ActionMenuBody.Span(Find.ByText("View Source")); }
        }
        
        public Span RefreshActionMenuItem
        {
            get { return ActionMenuBody.Span(Find.ByText("Refresh")); }
        }
        public Span MoveActionMenuItem
        {
            get { return ActionMenuBody.Span(Find.ByText("Move")); }
        }
        
        
        #endregion

        #region Divs
        public Div ActionMenuManageDiv
        {
            get { return IEInstance.Div(Find.ByClass("dnnActionMenuTag")); }
        }
        public Div UsageDetailsDiv
        {
            get { return IEInstance.Div(Find.ById(s => s.EndsWith("UsageDetails_UP"))); }
        }
        public Div ActionMenuBody
        {
            get { return IEInstance.Div(Find.ByClass("dnnActionMenu ui-draggable")); }
        }
        #endregion

        #region Links
        public Link InstallModuleLink
        {
            get { return IEInstance.Link(Find.ByTitle("Install Module")); }
        }
        public Link CreateNewModuleLink
        {
            get { return IEInstance.Link(Find.ByTitle("Create New Module")); }
        }
        public Link DeleteActionMenuItem
        {
            get { return ActionMenuBody.Link(Find.ByText("Delete")); }
        }
        public Link SettingsActionMenuItem
        {
            get { return ActionMenuBody.Link(Find.ByText(s => s.Contains("Settings"))); }
        }
        public Link MoveModuleBottomLink
        {
            get { return ActionMenuBody.Link(Find.ByText("Bottom")); }
        }
        public Link MoveModuleDownLink
        {
            get { return ActionMenuBody.Link(Find.ByText("Down")); }
        }
        public Link MoveModuleTopLink
        {
            get { return ActionMenuBody.Link(Find.ByText("Top")); }
        }
        public Link MoveModuleUpLink
        {
            get { return ActionMenuBody.Link(Find.ByText("Up")); }
        }
        public Link MoveLeftPaneLink
        {
            get { return ActionMenuBody.Link(Find.ByText("To LeftPane")); }
        }
        public Link MoveRightPaneLink
        {
            get { return ActionMenuBody.Link(Find.ByText("To RightPane")); }
        }
        public Link MoveBottomPaneLink
        {
            get { return ActionMenuBody.Link(Find.ByText("To BottomPane")); }
        }
        public Link MoveTopPaneLink
        {
            get { return ActionMenuBody.Link(Find.ByText("To TopPane")); }
        }
        #endregion

        #region Images
        public Image ModuleActionMenuImage
        {
            get { return IEInstance.Image(Find.ById(new Regex(@"dnn_ctr\d\d\d_dnnACTIONS_ctldnnACTIONSicn\d", RegexOptions.IgnoreCase))); }
        }
        #endregion


        #endregion

        #region Public Methods

        public Image GetActionMenuImageForModule(int moduleNum)
        {
            return IEInstance.Images.Filter(Find.ById(s => s.Contains("dnnACTIONS_ctldnnACTIONSicn")))[moduleNum];
        }

        public Image GetActionMenuImageForModuleInPane(string paneId)
        {
            return IEInstance.TableCell(Find.ById(paneId)).Image(Find.ById(s => s.Contains("dnnACTIONS_ctldnnACTIONSicn")));
        }

        public Span GetMoveActionMenuSpanForPane(string pane)
        {
            if (pane.CompareTo("Right") == 0)
            {
                return RightPaneCell.Table(Find.ById(s => s.Contains("dnnACTIONS_ctldnnACTIONS"))).Span(Find.ByText("Move"));
            }
            else if (pane.CompareTo("Left") == 0)
            {
                return LeftPaneCell.Table(Find.ById(s => s.Contains("dnnACTIONS_ctldnnACTIONS"))).Span(Find.ByText("Move"));
            }
            else if (pane.CompareTo("Content") == 0)
            {
                return ContentPane.Table(Find.ById(s => s.Contains("dnnACTIONS_ctldnnACTIONS"))).Span(Find.ByText("Move"));
            }
            else if (pane.CompareTo("Bottom") == 0)
            {
                return BottomPaneDiv.Table(Find.ById(s => s.Contains("dnnACTIONS_ctldnnACTIONS"))).Span(Find.ByText("Move"));
            }
            else if (pane.CompareTo("Top") == 0)
            {
                return TopPaneDiv.Table(Find.ById(s => s.Contains("dnnACTIONS_ctldnnACTIONS"))).Span(Find.ByText("Move"));
            }
            else
            {
                return null;
            }
        }

        public Span GetMoveActionMenuSpanForPaneAndModuleNumber(string pane, int moduleNum)
        {
            if (pane.CompareTo("Right") == 0)
            {
                return RightPaneCell.Tables.Filter(Find.ById(s => s.Contains("dnnACTIONS_ctldnnACTIONS")))[moduleNum].Span(Find.ByText("Move"));
            }
            else if (pane.CompareTo("Left") == 0)
            {
                return LeftPaneCell.Tables.Filter(Find.ById(s => s.Contains("dnnACTIONS_ctldnnACTIONS")))[moduleNum].Span(Find.ByText("Move"));
            }
            else if (pane.CompareTo("Content") == 0)
            {
                return ContentPane.Tables.Filter(Find.ById(s => s.Contains("dnnACTIONS_ctldnnACTIONS")))[moduleNum].Span(Find.ByText("Move"));
            }
            else if (pane.CompareTo("Bottom") == 0)
            {
                return BottomPaneDiv.Tables.Filter(Find.ById(s => s.Contains("dnnACTIONS_ctldnnACTIONS")))[moduleNum].Span(Find.ByText("Move"));
            }
            else if (pane.CompareTo("Top") == 0)
            {
                return TopPaneDiv.Tables.Filter(Find.ById(s => s.Contains("dnnACTIONS_ctldnnACTIONS")))[moduleNum].Span(Find.ByText("Move"));
            }
            else
            {
                return null;
            }
        }

  

        #endregion
    }
}